package com.example.demo.service.impl;

import com.example.demo.dbo.Dept;
import com.example.demo.dbo.User;
import com.example.demo.event.OrderEvent;
import com.example.demo.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @program: demo
 * @description:
 * @author: Mr.Wang
 * @create: 2020-04-28 13:27
 **/
@Component
public class OrderEventImpl implements ApplicationListener<OrderEvent> {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public void onApplicationEvent(OrderEvent orderEvent) {
        Dept dept = new Dept();
        //dept.setDeptNo("1");
        //dept.setDeptName("部门1");
        User user = (User) orderEvent.getSource();
        dept.setDeptNo(user.getUserId());
        dept.setDeptName(user.getName());
        deptMapper.insert(dept);
        System.out.println("我在监听：" + orderEvent.toString());
    }
}
